package org.sbbs.base.tenant.web;

import java.util.List;
import org.sbbs.base.tenant.dao.PersonRepo;
import org.sbbs.base.tenant.entity.Person;
import org.sbbs.base.tenant.entity.PersonDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/people")
public class PersonController {

    private final PersonRepo personRepository;

    public PersonController(PersonRepo personRepository) {
        this.personRepository = personRepository;
    }

    @PostMapping
    public Person save(@RequestBody PersonDto personDto) {
        return personRepository.save(personDto.createPerson());
    }

    @GetMapping
    private List<Person> all() {
        return personRepository.findAll();
    }
}
